# -*- coding: UTF-8 -*-
'''
@Project ：pythonProject 
@File    ：py3.11.py
@Author  ：siwei
@Date    ：2023/10/16 22:29 
@other   ：str.print---->print(str)
'''
#python3.11特性
#1.结构的模式匹配
data = eval(input("请输入要匹配的数据:"))
# eval() 函数执行去掉引号后的字符内容，可用于将字符串转换为list、dict、tuple
match data:
    case {'name': '张三',"age": 18}:
        print("字典")
    case [1,2,3]:
        print("列表")
    case (10,20,30):
        print("元组")
    case _:
        print("其他")

#2.合并字典运算符
a = {"a": 1, "b": 2}
b = {"c": 3, "d": 4}
c = a | b
print(c)    # {'a': 1, 'b': 2, 'c': 3, 'd': 4}

#3.同步迭代
fruits = {"apple", "banana", "cherry"}  #集合是无序的,执行后会随机打印一个结果
# fruits = ["apple", "banana", "cherry"]  #列表是有序的,执行后会按照顺序打印
counts = [10,3,4]
for f, c in zip(fruits, counts):
    match f,c :
        case "apple", 10:
            print("10个苹果")
        case "banana", 3:
            print("3个香蕉")
        case "cherry", 4:
            print("4个樱桃")

